-- round_self_recover
-- created by panyl
-- 每回合回复

return {
    apply = function(prop, baseValue)
        return math.modf(prop[3] * baseVAlue / 1000);
    end,

    -- 每回合触发
    trigger = function(who, prop, arg)
        local attrib = tostring(prop[2]);
        local value;

        -- 回复生命、魔法
        if attrib == "hp" or attrib == "mp" then
            local max = who:getMaxHp();
            local curr = who:getHp();
            if attrib == "mp" then
                max = who:getMaxMp();
                curr = who:getMp();
            end

            -- 不能超过上限
            value = FormulaM.invoke("CALC_BIG_DIVISION", max, tonumber(prop[3]), 1000);
            value = math.min(value, max - curr);
        else
            -- 攻击、魔力保底1点
            value = math.modf(tonumber(prop[3]) * who:queryAttrib(attrib) / 1000);
            value = math.max(value, 1);
        end

        if value <= 0 then
            return 0;
        end

        if who.type == OBJECT_TYPE_USER then
            BonusM.doBonus({ 2, attrib, value, }, "round_self_recover");
        else
            who:addAttrib(attrib, value);
        end

    return value;
    end,

    record = function(target, prop, path)
        return false;
    end
};
